#!/bin/sh
#
# Patch all of the chroot jails created with 'create_chroot'. Before
# doing this check to see if any of the files in the repository have
# been changed. After doing this create a new database for the user.
#
#
# enchroot is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# enchroot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with enchroot. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (c) 2010 charles@kollar.com
#

#
# Global configuraiton/options are set in this file...
. /usr/local/etc/enchroot.conf


for CHROOT_USERNAME in $( ls $HOME_CHROOT )
do
  JAILPATH=$HOME_CHROOT/$CHROOT_USERNAME
  if ! [ -f $AIDEDIR/$CHROOT_USERNAME/aide.conf ] ; then
    echo "No aide configuration file for '$CHROOT_USERNAME' ?"
  else
    echo ""
    echo "*****Checking chroot jail '$JAILPATH' for changes..."
    echo ""
    cp $AIDEDIR/$CHROOT_USERNAME/aide.db.new $AIDEDIR/$CHROOT_USERNAME/aide.db
    aide --check --config=$AIDEDIR/$CHROOT_USERNAME/aide.conf
    echo ""
    echo "*****Checking chroot jail '$JAILPATH' for patches..."
    echo ""
# http://wiki.opensuse.org/Package_repositories
    zypper --root $JAILPATH refresh
    zypper --root $JAILPATH patch --no-recommends --auto-agree-with-licenses
    echo ""
    echo "*****Checking chroot jail '$JAILPATH' for changes..."
    echo ""
    aide --init --config=$AIDEDIR/$CHROOT_USERNAME/aide.conf
  fi
done
